package cn.train.controler;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.model.Carpiao;
import cn.train.service.EditTrainServices;
import cn.train.util.Pageutil;

@WebServlet("/EditTrainServlet")
public class EditTrainServlet extends HttpServlet {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		EditTrainServices ets=new EditTrainServices();
		List<Carpiao> list=new ArrayList<Carpiao>();
		String currPage = request.getParameter("pageIndex");
		if (currPage == null) {
			currPage = "1";
		}
		int pageIndex = Integer.parseInt(currPage);
		if(pageIndex<=0){
			pageIndex=1;
		}
		// 鎬绘潯鏁�
		int count = ets.getCount();
		Pageutil pu = new Pageutil();
		// 鎬婚〉鏁�
		int totalPage = pu.getTotalPage(count, Pageutil.pageSize);
		if(pageIndex>totalPage){
			pageIndex=totalPage;
		}
		
		list=ets.getUserByPage(pageIndex, Pageutil.pageSize);
		request.setAttribute("list", list);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("totalPage", totalPage);
		request.getRequestDispatcher("back/editTrain.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
